import json
import pymysql

conn = pymysql.connect(
    host='localhost',  # mysql服务器地址
    port=3306,  # 端口号
    user='root',  # 用户名
    passwd='root',  # 密码
    db='yw',  # 数据库名称
    charset='utf8',  # 连接编码，根据需要填写
)
cur = conn.cursor()  # 创建并返回游标
path = r'../yw_crawl/yw-1-大学图书馆学报10-15.json'
f = open(path, 'r',encoding='utf-8')
for i in f.readlines():
    jsonstr = json.loads(i)
    sno = jsonstr['sno']
    lymp = jsonstr['lymp']
    id = jsonstr['id']
    znum = jsonstr['znum']
    yz_lists = jsonstr['yz_lists']
    print(sno)
    print(lymp)
    print(id)
    print(znum)
    print(yz_lists)
    sql = '''insert into `大学图书馆学报` (sno,lymp,id,znum,yz_lists) values ("''' + sno + '''","''' + lymp+ '''","''' + id + '''","''' + znum + '''","''' + yz_lists + '''");'''
    print(sql)
    try:
        cur.execute(sql)
        conn.commit()
    except Exception as e:
        continue
conn.close()